package shiyan.second;

import java.util.Scanner;

/**
 * Created by mc on 2016/8/2.
 */
public class Complex {
    protected int a;

    protected int b;

    public Complex(int a, int b) {
        this.a = a;
        this.b = b;
    }

    public String toString() {
        return this.a + " + " + this.b + "i";
    }

    public static Complex addition(Complex complex1, Complex complex2) {
        int a = complex1.a + complex2.a;
        int b = complex1.b + complex2.b;
        return new Complex(a, b);
    }

    public static Complex subtract(Complex complex1, Complex complex2) {
        int a = complex1.a - complex2.a;
        int b = complex1.b - complex2.b;
        return new Complex(a, b);
    }

    public static Complex multiplication(Complex complex1, Complex complex2) {
        int a = complex1.a * complex2.a - complex1.b * complex2.b;
        int b = complex1.b * complex2.a + complex1.a * complex2.b;
        return new Complex(a, b);
    }
}


class ComplexMain {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入两个复数的实部和虚部：（a+bi、c+di）");
        System.out.printf("a =");
        int a = scanner.nextInt();
        System.out.printf("b =");
        int b = scanner.nextInt();
        System.out.printf("c =");
        int c = scanner.nextInt();
        System.out.printf("d =");
        int d = scanner.nextInt();
        Complex fushu1 = new Complex(a, b);
        Complex fushu2 = new Complex(c, d);
        while (true) {
            System.out.println("请输入需要进行的运算：1、ADD 2、SUBTRACT 3、MULTIPLY ");
            int choice = scanner.nextInt();
            switch (choice) {
                case 1:
                    System.out.println(Complex.addition(fushu1, fushu2));
                    break;
                case 2:
                    System.out.println(Complex.subtract(fushu1, fushu2));
                    break;
                case 3:
                    System.out.println(Complex.multiplication(fushu1, fushu2));
                    break;
                default:
                    System.out.println("错误");
            }
        }
    }
}